package othello.server.controller;

import java.util.logging.Logger;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import othello.server.service.LoungeImpl;
import othello.server.service.OthelloServiceImpl;
import othello.shared.model.StateAtLounge;

/**
 * エントリー状態、ゲーム状態のリセット処理を行うコントローラー
 * 
 * @author onjiro.mohyahya
 */
public class ResetController extends Controller {

	private static final Logger LOGGER = Logger.getLogger(ResetController.class
			.getName());

	private static final LoungeImpl loungeService = new LoungeImpl();
	private static final OthelloServiceImpl othelloService = new OthelloServiceImpl();

	@Override
	public Navigation run() throws Exception {
		final String sessionId = this.request.getSession().getId();
		LOGGER.entering(ResetController.class.getName(), "run", sessionId);

		StateAtLounge state = loungeService.reset(sessionId);
		if (state != null && state.getGameBoardId() != null) {
			othelloService.reset(state.getGameBoardId());
		}

		LOGGER.exiting(ResetController.class.getName(), "run");
		return redirect("index");
	}
}
